package com.xmu.prcs.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.xmu.prcs.action.bean.KindBean;
import com.xmu.prcs.action.bean.KindKeBean;
import com.xmu.prcs.action.bean.KindShuBean;
import com.xmu.prcs.action.bean.PlantInfoBean;
import com.xmu.prcs.action.bean.PlantLocationBean;
import com.xmu.prcs.action.bean.SubjectBean;
import com.xmu.prcs.dao.ImageDao;
import com.xmu.prcs.dao.KindKeDao;
import com.xmu.prcs.dao.KindShuDao;
import com.xmu.prcs.dao.LocationDao;
import com.xmu.prcs.dao.PlantDao;
import com.xmu.prcs.dao.SubjectDao;
import com.xmu.prcs.entity.Image;
import com.xmu.prcs.entity.KindKe;
import com.xmu.prcs.entity.KindShu;
import com.xmu.prcs.entity.Location;
import com.xmu.prcs.entity.Plant;
import com.xmu.prcs.entity.Subject;
import com.xmu.prcs.service.PlantInfoManager;
import com.xmu.prcs.util.DictionaryUtil;
import com.xmu.prcs.util.PageBean;
import com.xmu.prcs.util.ResultBean;

public class PlantInfoManagerImpl implements PlantInfoManager {
	
	private PlantDao plantDao;
	private ImageDao imageDao;
	private LocationDao locationDao;
	private KindShuDao kindShuDao;
	private SubjectDao subjectDao;
	private KindKeDao kindKeDao;

	public PlantDao getPlantDao() {
		return plantDao;
	}

	public void setPlantDao(PlantDao plantDao) {
		this.plantDao = plantDao;
	}

	public ImageDao getImageDao() {
		return imageDao;
	}

	public void setImageDao(ImageDao imageDao) {
		this.imageDao = imageDao;
	}

	public LocationDao getLocationDao() {
		return locationDao;
	}

	public void setLocationDao(LocationDao locationDao) {
		this.locationDao = locationDao;
	}

	public KindShuDao getKindShuDao() {
		return kindShuDao;
	}

	public void setKindShuDao(KindShuDao kindShuDao) {
		this.kindShuDao = kindShuDao;
	}

	public SubjectDao getSubjectDao() {
		return subjectDao;
	}

	public void setSubjectDao(SubjectDao subjectDao) {
		this.subjectDao = subjectDao;
	}

	public KindKeDao getKindKeDao() {
		return kindKeDao;
	}

	public void setKindKeDao(KindKeDao kindKeDao) {
		this.kindKeDao = kindKeDao;
	}

	public void addPlant(PlantInfoBean plant) {
		
		Plant newPlant = this.plantBean2Entity(plant);
		newPlant.setUploadTime(new Date());
		//更新植物图像
		Set<Image> images = new HashSet<Image>();
		for(int i = 0; i < plant.getImagePaths().size(); i++){
			Image image = new Image();
			image.setImagePath(plant.getImagePaths().get(i));
			imageDao.save(image);
			imageDao.flush();
			
			images.add(image);
		}	
		newPlant.setImages(images);
		//更新植物地理位置
		if (plant.getLongitude() != null && plant.getLongitude().size() != 0) {
			Set<Location> locations = new HashSet<Location>();
			for (int i = 0; i < plant.getLongitude().size(); i++) {
				Location location = new Location();
				location.setLongitude(plant.getLongitude().get(i));
				location.setLatitude(plant.getLatitude().get(i));
				locationDao.save(location);
				locationDao.flush();

				locations.add(location);
			}
			newPlant.setLocations(locations);
		}
		//保存新的植物实体
		plantDao.save(newPlant);
		
		KindKe kindKe = kindKeDao.get(Integer.parseInt(plant.getKindKe()));
		if(kindKe != null){
			newPlant.setKindKe(kindKe.getKindName());
		}
		
		//更新植物与kindshu、subject之间的表关系
		KindShu kindshu = kindShuDao.get(Integer.parseInt(plant.getKindShu()));
		if(kindshu != null){
			Set<Plant> plants = new HashSet<Plant>();
			if(kindshu.getPlants() != null){
				plants = kindshu.getPlants();
			}
			plants.add(newPlant);
			kindshu.setPlants(plants);
			kindShuDao.update(kindshu);
			newPlant.setKindShu(kindshu.getKindName());
		}
		if(plant.getSubject() != null && !plant.getSubject().equals("")){
			Subject subject = subjectDao.get(Integer.parseInt(plant.getSubject()));
			if(subject != null){
				Set<Plant> splants = new HashSet<Plant>();
				if(subject.getPlants() != null){
					splants = subject.getPlants();
				}
				splants.add(newPlant);
				subject.setPlants(splants);
				subjectDao.update(subject);
				newPlant.setSubjectName(subject.getSubjectName());
			}
		}
		plantDao.update(newPlant);
	}
	
	/**
	 * 将植物bean转换为实体对象
	 * @param plant
	 * @return
	 */
	public Plant plantBean2Entity(PlantInfoBean plant){
		Plant newPlant = new Plant();
		
		newPlant.setAlias(plant.getAlias());
		newPlant.setApplication(plant.getApplication());
		newPlant.setCampus(plant.getCampus());
		newPlant.setCharacteristic(plant.getCharacteristic());
		newPlant.setCulture(plant.getCulture());
		newPlant.setEnglishName(plant.getEnglishName());
		newPlant.setGrowPoint(plant.getGrowPoint());
		newPlant.setHabits(plant.getHabits());
//		newPlant.setKindKe(plant.getKindKe());
//		newPlant.setKindShu(plant.getKindShu());
		newPlant.setOriginPlace(plant.getOriginPlace());
		newPlant.setPlantName(plant.getPlantName());
		newPlant.setScientificName(plant.getScientificName());
//		newPlant.setSubjectName(plant.getSubject());
		
		return newPlant;
	}

	public boolean isPlantNameExist(String name) {
		List<Plant> list = plantDao.findByPropety(PlantDao.PLANT_NAME, name);
		if(list == null || list.size() == 0){
			return false;
		}
		return true;
	}

	public boolean isScientificNameExist(String name) {
		List<Plant> list = plantDao.findByPropety(PlantDao.SCIENTIFIC_NAME, name);
		if(list == null || list.size() == 0){
			return false;
		}
		return true;
	}

	public List<KindKeBean> getAllKindKe() {
		List<KindKe> list = null;
		list = kindKeDao.getAll();
		List<KindKeBean> kindKe = new ArrayList<KindKeBean>();
		if(list == null || list.size() == 0){
			return null;
		}
		for(KindKe kind : list){
			KindKeBean bean = new KindKeBean();
			bean.setValue(kind.getIdKindKe().toString());
			bean.setKindKeName(kind.getKindName());
			kindKe.add(bean);
		}
		return kindKe;
	}

	public List<KindShuBean> getKindShuByKindKe(String kindKe) {
		
		KindKe kindke = null;
		kindke = kindKeDao.get(Integer.parseInt(kindKe));
		if(kindke == null){
			return null;
		}
		Set<KindShu> kindShus = kindke.getKindShus();
		if(kindShus == null || kindShus.size() == 0){
			return null;
		}
		List<KindShuBean> kindShu = new ArrayList<KindShuBean>();
		for(KindShu kindshu : kindShus){
			KindShuBean bean = new KindShuBean();
			bean.setValue(kindshu.getIdKindShu().toString());
			bean.setKindShuName(kindshu.getKindName());
			kindShu.add(bean);
		}
		return kindShu;
	}

	public List<SubjectBean> getAllSubjectName(){
		List<Subject> subjects = null;
		subjects = subjectDao.getAll();
		if(subjects == null || subjects.size() == 0){
			return null;
		}
		List<SubjectBean> subjectNames = new ArrayList<SubjectBean>();
		for(Subject subject : subjects){
			SubjectBean bean = new SubjectBean();
			bean.setValue(subject.getIdSubject().toString());
			bean.setSubjectName(subject.getSubjectName());
			subjectNames.add(bean);
		}
		return subjectNames;
	}

	public boolean addKindKe(String kindKe) {
		System.out.println("kindke:" + kindKe);
		List<KindKe> kindKes = kindKeDao.findByProperty(KindKeDao.KIND_NAME, kindKe);
		if(kindKes != null && kindKes.size()!= 0){
			System.out.println("exist");
			return false;
		}
		//不存在的话，就建立这个新的分类科
		KindKe ke = new KindKe();
		ke.setKindName(kindKe);
		ke.setUpdateTime(new Date());
		kindKeDao.save(ke);
		return true;
	}

	public boolean addKindShu(String idKindKe, String kindShu) {
		System.out.println("kindshu:" + kindShu + ",idKindKe:" + idKindKe);
		List<KindShu> shus = kindShuDao.findKindShuByPropety(KindShuDao.KIND_NAME, kindShu);
		if(shus != null && shus.size() != 0){
			return false;
		}
		//不存在的话，就建立这个新的分类属
		KindShu shu = new KindShu();
		shu.setKindName(kindShu);
		shu.setUpdateTime(new Date());
		kindShuDao.save(shu);
		kindShuDao.flush();
		//更新分类科下的分类属
		KindKe ke = kindKeDao.get(Integer.parseInt(idKindKe));
		Set<KindShu> kindshus = ke.getKindShus();
		kindshus.add(shu);
		ke.setKindShus(kindshus);
		kindKeDao.update(ke);
		
		return true;
	}

	public KindKe getKindKeByProperty(Object param) {
		List<KindKe> list = null;
		list = kindKeDao.findByProperty(KindKeDao.KIND_NAME, param);
		if(list == null || list.size() == 0){
			return null;
		}
		KindKe ke = list.get(0);
		return ke;
	}

	public KindShu getKindShuByProperty(Object param) {
		List<KindShu> list = null;
		list = kindShuDao.findKindShuByPropety(KindShuDao.KIND_NAME, param);
		if(list == null || list.size() == 0){
			return null;
		}
		KindShu shu = list.get(0);
		return shu;
	}

	public ResultBean getPlant4Page(PageBean page, String idSubject, String idKindShu, String plantName) {
		int idsub = 0;
		if(idSubject != null && !idSubject.equals("")){
			idsub = Integer.parseInt(idSubject);
		}
		int idshu = 0;
		if(idKindShu != null && !idKindShu.equals("")){
			idshu = Integer.parseInt(idKindShu);
		}
		int count = plantDao.countPlant(idsub, idshu, plantName);
		PageBean pagebean = new PageBean(count);
		pagebean.setCurrentPage(page.getCurrentPage());
		
		List<Plant> plantList = plantDao.find4Page(page.getBeginIndex(), page.getPageSize(), idsub, idshu, plantName);
		
		List<PlantInfoBean> beanList = new ArrayList<PlantInfoBean>();
		if(plantList != null && plantList.size() != 0){
			PlantInfoBean bean = new PlantInfoBean();
			for(Plant p : plantList){
				bean = this.PlantEntity2Bean(p);
				beanList.add(bean);
			}
		}
		ResultBean result = new ResultBean();
		result.setPage(pagebean);
		result.setContent(beanList);
		return result;
	}
	
	/**
	 * 将plant实体转换为页面bean
	 * @param plant
	 * @return
	 */
	public PlantInfoBean PlantEntity2Bean(Plant plant){
		PlantInfoBean bean = new PlantInfoBean();
		
		bean.setIdPlant(plant.getIdPlant());
		bean.setPlantName(plant.getPlantName());
		bean.setAlias(plant.getAlias());
		bean.setApplication(plant.getApplication());
		bean.setCampus(plant.getCampus());
		bean.setCharacteristic(plant.getCharacteristic());
		bean.setCulture(plant.getCulture());
		bean.setEnglishName(plant.getEnglishName());
		bean.setGrowPoint(plant.getGrowPoint());
		bean.setHabits(plant.getHabits());
		bean.setKindKe(plant.getKindKe());
		bean.setKindShu(plant.getKindShu());
		bean.setOriginPlace(plant.getOriginPlace());
		bean.setScientificName(plant.getScientificName());
		bean.setSubject(plant.getSubjectName());
		
		Set<Image> images = plant.getImages();
		List<String> image = new ArrayList<String>();
		if(images == null || images.size() == 0){
			image.add(DictionaryUtil.DERAULT_PLANT_PATH);
		}else{
			for(Image i : images){
				if(i.getImagePath().equals(DictionaryUtil.DEFAULT_PHOTO)){
					image.add(DictionaryUtil.DERAULT_PLANT_PATH);
				}else{
					image.add(i.getImagePath());
				}
			}
		}
		bean.setImagePaths(image);
		
		Set<Location> locations = plant.getLocations();
		List<String> longitude = new ArrayList<String>();
		List<String> latitude = new ArrayList<String>();
		if(locations != null && locations.size() != 0){
			for(Location location : locations){
				longitude.add(location.getLongitude());
				latitude.add(location.getLatitude());
			}
		}
		bean.setLongitude(longitude);
		bean.setLatitude(latitude);
		
		return bean;
	}

	public PlantInfoBean getPlantByName(String name) {
		PlantInfoBean bean = new PlantInfoBean();
		List<Plant> list = plantDao.findByPropety(PlantDao.PLANT_NAME, name);
		if(list != null && list.size() != 0){
			Plant plant = list.get(0);
			bean = this.PlantEntity2Bean(plant);
		}
		return bean;
	}

	public Subject getSubjectByName(String name) {
		List<Subject> list = subjectDao.getSubjectsByPropety(SubjectDao.SUBJECT_NAME, name);
		if(list == null || list.size() == 0){
			return null;
		}
		
		return list.get(0);
	}

	public boolean collectPlant(int iduser, int idPlant) {
		return false;
	}

	public boolean deletePlant(int idPlant) {
		plantDao.remove(idPlant);
		return false;
	}

	public boolean modifyPlant(PlantInfoBean bean) {
		Plant plant = plantDao.get(bean.getIdPlant());
		
		plant.setAlias(bean.getAlias());
		plant.setApplication(bean.getApplication());
		plant.setCampus(bean.getCampus());
		plant.setCharacteristic(bean.getCharacteristic());
		plant.setCulture(bean.getCulture());
		plant.setEnglishName(bean.getEnglishName());
		plant.setGrowPoint(bean.getGrowPoint());
		plant.setHabits(bean.getHabits());
		plant.setOriginPlace(bean.getOriginPlace());
		plant.setPlantName(bean.getPlantName());
		plant.setScientificName(bean.getScientificName());

		//		plant.setIdPlant(bean.getIdPlant());
		plant.setUploadTime(new Date());
		//更新植物图像
		Set<Image> images = new HashSet<Image>();
		for(int i = 0; i < bean.getImagePaths().size(); i++){
			Image image = new Image();
			image.setImagePath(bean.getImagePaths().get(i));
			imageDao.save(image);
			imageDao.flush();
			
			images.add(image);
		}	
		plant.setImages(images);
		//更新植物地理位置
		if (bean.getLongitude() != null && bean.getLongitude().size() != 0) {
			Set<Location> locations = new HashSet<Location>();
			for (int i = 0; i < bean.getLongitude().size(); i++) {
				Location location = new Location();
				location.setLongitude(bean.getLongitude().get(i));
				location.setLatitude(bean.getLatitude().get(i));
				locationDao.save(location);
				locationDao.flush();

				locations.add(location);
			}
			plant.setLocations(locations);
		}
		KindKe kindKe = kindKeDao.get(Integer.parseInt(bean.getKindKe()));
		if(kindKe != null){
			plant.setKindKe(kindKe.getKindName());
		}
		
		//更新植物与kindshu、subject之间的表关系
		KindShu kindshu = kindShuDao.get(Integer.parseInt(bean.getKindShu()));
//		Hibernate.initialize(kindshu.getPlants());
		if(kindshu != null && !kindshu.getKindName().equals(plant.getKindShu())){
			Set<Plant> plants = new HashSet<Plant>();
			Set<Plant> set = kindshu.getPlants();
			if(set != null){
				plants = set;
			}
			plants.add(plant);
			kindshu.setPlants(plants);
			kindShuDao.update(kindshu);
			plant.setKindShu(kindshu.getKindName());
		}
		if(bean.getSubject() != null && !bean.getSubject().equals("")){
			Subject subject = subjectDao.get(Integer.parseInt(bean.getSubject()));
			if(subject != null && !subject.equals(plant.getSubjectName())){
				Set<Plant> splants = new HashSet<Plant>();
				Set<Plant> set = subject.getPlants();
				if(set != null){
					splants = set;
				}
				splants.add(plant);
				subject.setPlants(splants);
				subjectDao.update(subject);
				plant.setSubjectName(subject.getSubjectName());
			}
		}
		plantDao.update(plant);
		System.out.println("update plant");
		return true;
	}

	public ResultBean getSubject4Page(PageBean page) {
		int count = subjectDao.countSubject();
		PageBean pagebean = new PageBean(count);
		pagebean.setCurrentPage(page.getCurrentPage());
		List<Subject> subjectList = subjectDao.getSubject4Page(page.getBeginIndex(), page.getPageSize());
		
		List<SubjectBean> beanList = new ArrayList<SubjectBean>();
		if(subjectList != null && subjectList.size() != 0){
			System.out.println("subjectlist size:" + subjectList.size());
			SubjectBean bean;
			for(Subject s : subjectList){
				bean = new SubjectBean();
				bean.setValue(s.getIdSubject().toString());
				bean.setSubjectName(s.getSubjectName());
				bean.setSubjectInfo(s.getSubjectInfo());
				beanList.add(bean);
			}
		}
		ResultBean result = new ResultBean();
		result.setPage(pagebean);
		result.setContent(beanList);
		return result;
	}

	public ResultBean getPlant4PageBySubject(int idSubject, PageBean page) {
		Subject subject = subjectDao.get(idSubject);
		Set<Plant> set = subject.getPlants();
		List<Plant> plantList = new ArrayList(set);
		PageBean pagebean;
		List<PlantInfoBean> plants = new ArrayList<PlantInfoBean>();
		if(plantList != null){
			pagebean = new PageBean(plantList.size());
			pagebean.setCurrentPage(page.getCurrentPage());
			PlantInfoBean bean;
			for(int i = (page.getCurrentPage() - 1) * page.getPageSize(); i < plantList.size() && i < page.getPageSize();i++){
				bean = new PlantInfoBean();
				bean = this.PlantEntity2Bean(plantList.get(i));
				plants.add(bean);
			}
		}else{
			pagebean = new PageBean();
		}
		ResultBean result = new ResultBean();
		result.setPage(pagebean);
		result.setContent(plants);
		return result;
	}

	public boolean addSubject(SubjectBean bean) {
		Subject subject = new Subject();
		
		subject.setSubjectName(bean.getSubjectName());
		subject.setSubjectInfo(bean.getSubjectInfo());
		subject.setUpdateTime(new Date());
		
		subjectDao.save(subject);
		return true;
	}

	public SubjectBean getSubjectById(int idSubject) {
		SubjectBean bean = new SubjectBean();
		Subject subject = subjectDao.get(idSubject);
		if(subject != null){
			bean.setValue(subject.getIdSubject().toString());
			bean.setSubjectName(subject.getSubjectName());
			bean.setSubjectInfo(subject.getSubjectInfo());
		}
		return bean;
	}
	
	public boolean modifySubject(SubjectBean bean){
		Subject subject = subjectDao.get(Integer.parseInt(bean.getValue()));
		if(subject != null){
			subject.setSubjectName(bean.getSubjectName());
			subject.setSubjectInfo(bean.getSubjectInfo());
			subjectDao.update(subject);
		}
		return true;
	}

	public ResultBean getKindKe4Page(PageBean page, String kindName) {
		int count = kindKeDao.countKindKe(kindName);
		PageBean pagebean = new PageBean(count);
		pagebean.setCurrentPage(page.getCurrentPage());
		
		List<KindKe> kelist = kindKeDao.get4Page(page.getBeginIndex(), page.getPageSize(), kindName);
		List<KindBean> beanlist = new ArrayList<KindBean>();
		KindBean bean;
		for(KindKe ke : kelist){
			bean = new KindBean();
			bean.setIdKind(ke.getIdKindKe().toString());
			bean.setKindName(ke.getKindName());
			bean.setNumber(0);
			String image = DictionaryUtil.DERAULT_PLANT_PATH;
			List<KindShu> shulist = new ArrayList(ke.getKindShus());
			if(shulist != null && shulist.size() != 0){
				bean.setNumber(shulist.size());
				List<Plant> plantlist = new ArrayList(shulist.get(0).getPlants());
				if(plantlist != null && plantlist.size() != 0){
					List<Image> imagelist = new ArrayList(plantlist.get(0).getImages());
					if(imagelist != null && imagelist.size() != 0){
						image = imagelist.get(0).getImagePath();
						if(image.equals(DictionaryUtil.DEFAULT_PHOTO)){
							image = DictionaryUtil.DERAULT_PLANT_PATH;
						}
					}
				}
			}
			bean.setImage(image);
			beanlist.add(bean);
		}
		ResultBean result = new ResultBean();
		result.setContent(beanlist);
		result.setPage(pagebean);
		return result;
	}

	public ResultBean getKindShu4Page(PageBean page, String kindName,
			String idKindKe) {
		int kindKe = 0;
		if(idKindKe != null && !idKindKe.equals("")){
			kindKe = Integer.parseInt(idKindKe);
		}
		int count = kindShuDao.countKindShu(kindKe, kindName);
		PageBean pagebean = new PageBean(count);
		pagebean.setCurrentPage(page.getCurrentPage());
		
		List<KindShu> shulist = kindShuDao.findKindShu4Page(page.getBeginIndex(), page.getPageSize(), kindKe, kindName);
		List<KindBean> beanlist = new ArrayList<KindBean>();
		KindBean bean ;
		for(KindShu shu : shulist){
			bean = new KindBean();
			bean.setIdKind(shu.getIdKindShu().toString());
			bean.setKindName(shu.getKindName());
			bean.setNumber(0);
			List<Plant> plantList = new ArrayList(shu.getPlants());
			String image = DictionaryUtil.DERAULT_PLANT_PATH;
			if(plantList != null && plantList.size() != 0){
				bean.setNumber(plantList.size());
				List<Image> imagelist = new ArrayList(plantList.get(0).getImages());
				if(imagelist != null && imagelist.size() != 0){
					image = imagelist.get(0).getImagePath();
					if(image.equals(DictionaryUtil.DEFAULT_PHOTO)){
						image = DictionaryUtil.DERAULT_PLANT_PATH;
					}
				}
			}
			bean.setImage(image);
			beanlist.add(bean);
		}
		ResultBean result = new ResultBean();
		result.setContent(beanlist);
		result.setPage(pagebean);
		return result;
	}

	public List<PlantLocationBean> getPlantAndLocation() {
		List<PlantLocationBean> beans = new ArrayList<PlantLocationBean>();
		List<Plant> plants = plantDao.getAll();
		if(plants != null && plants.size() != 0){
			PlantLocationBean bean;
			String image;
			for(Plant plant : plants){
				Set<Location> locations = plant.getLocations();
				if(locations != null && locations.size() != 0){
					List<Image> images = new ArrayList(plant.getImages());
					image = images.get(0).getImagePath();
					if(image.equals(DictionaryUtil.DEFAULT_PHOTO)){
						image = DictionaryUtil.DERAULT_PLANT_PATH;
					}
					for(Location loc : locations){
						bean = new PlantLocationBean();
						if(plant.getAlias()==null){
							bean.setAlias(" ");
						}else{
							bean.setAlias(plant.getAlias());
						}
						bean.setIdPlant(plant.getIdPlant());
						bean.setPlantName(plant.getPlantName());
						if(plant.getScientificName() == null){
							bean.setScientificName("");
						}else{
							bean.setScientificName(plant.getScientificName());
						}
						bean.setImage(image);
						bean.setLatitude(loc.getLatitude());
						bean.setLongitude(loc.getLongitude());
						beans.add(bean);
					}
				}
			}
		}
		return beans;
	}

	public boolean deleteSubject(String idSubject) {
		if(idSubject == null || idSubject.equals("")){
			return false;
		}
		try{
			int ids = Integer.parseInt(idSubject);
			subjectDao.remove(ids);
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		
		return true;
	}

	public boolean isSubjectNameExist(String subjectName, int idSubject) {
		List<Subject> list = null;
		list = subjectDao.getSubjectsByPropety(SubjectDao.SUBJECT_NAME, subjectName);
		if(list != null && list.size() != 0){
			if(list.size() == 1 && list.get(0).getIdSubject().equals(idSubject)){
				return false;
			}
			return true;//系统中存在此专题名
		}
		return false;
	}

	public boolean deleteKindKe(int kind) {
		if(kind == 0){
			return false;
		}
		kindKeDao.remove(kind);
		return true;
	}

	public boolean deleteKindShu(int kind) {
		if(kind == 0){
			return false;
		}
		kindShuDao.remove(kind);
		return true;
	}

	public List<PlantInfoBean> getPlants4Index() {
		List<PlantInfoBean> list = new ArrayList<PlantInfoBean>();
		List<Plant> plants = plantDao.find4Page(0, 6, 0, 0, null);
		if(plants != null && plants.size() != 0){
			PlantInfoBean bean;
			for(Plant plant : plants){
				bean = new PlantInfoBean();
				bean = this.PlantEntity2Bean(plant);
				list.add(bean);
			}
		}
		return list;
	}
}
